package com.sskj.mine.ui.activity;


import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.lib.router.provider.LogoutProvider;
import com.sskj.lib.util.HideUtil;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.MineAccount;
import com.sskj.mine.component.DaggerUserDataComponent;
import com.sskj.mine.presenter.MineAccountActivityPresenter;
import com.sskj.mine.util.MineTipUtil;

import javax.inject.Inject;

import butterknife.BindView;
import de.hdodenhof.circleimageview.CircleImageView;

@Route(path = RConfig.MINE_ACCOUNT)
public class MineAccountActivity extends BaseActivity<MineAccountActivityPresenter> {
    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @BindView(R2.id.left_img)
    ImageView leftImg;
    @BindView(R2.id.left_tv)
    TextView leftTv;
    @BindView(R2.id.ivBack)
    LinearLayout ivBack;
    @BindView(R2.id.right_tv)
    TextView rightTv;
    @BindView(R2.id.ivRight)
    ImageView ivRight;
    @BindView(R2.id.user_head)
    CircleImageView userHead;
    @BindView(R2.id.user_mobile)
    TextView userMobile;
    @BindView(R2.id.account_out)
    TextView accountOut;
    @BindView(R2.id.account_money)
    TextView accountMoney;
    @BindView(R2.id.coin_money)
    TextView coinMoney;
    @BindView(R2.id.coin_money_finan)
    TextView coinMoneyFinan;
    @BindView(R2.id.tvUSDT)
    TextView tvUSDT;
    @BindView(R2.id.recharge)
    Button recharge;
    @BindView(R2.id.withdraw)
    Button withdraw;
    @Inject
    UserViewModel userViewModel;
    private UserData userData;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mine_account;
    }

    @Override
    public MineAccountActivityPresenter getPresenter() {
        return new MineAccountActivityPresenter();
    }

    @Override
    protected void initView() {
        DaggerUserDataComponent.create().inject(this);
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
                userMobile.setText(HideUtil.getPhoneHide(userData.getMobile()));
                accountMoney.setText("≈¥ " + userData.getZc_total().getTtl_cnymoney());
                tvUSDT.setText("≈" + userData.getZc_total().getTtl_money() + "USDT");
            } else {
                userData = null;
            }
        });
        tvTitle.setText(App.INSTANCE.getString(R.string.mine_mineAccountActivity1_j));
        rightTv.setText(App.INSTANCE.getString(R.string.mine_mineAccountActivity2_j));
        ClickUtil.click(rightTv, () -> {  // 明细
            ARouter.getInstance().build(RConfig.MINE_ASSET_RECORDS).navigation();
        });
        ClickUtil.click(accountOut, () -> {
            MineTipUtil.mineLogout(this, "", "", new MineTipUtil.OnInputList() {
                @Override
                public void onSure() {
                    LogoutProvider logoutProvider = ARouter.getInstance().navigation(LogoutProvider.class);
                    logoutProvider.logout();
                }
            }).show();
        });
        ClickUtil.click(recharge, () -> {  // 充币
            ARouter.getInstance().build(RConfig.MINE_RECHARGE).navigation();
        });
        ClickUtil.click(withdraw, () -> {  // 提币
            ARouter.getInstance().build(RConfig.MINE_WITHDRAW).navigation();
        });
    }

    @Override
    protected void initData() {
        super.initData();
        mPresenter.getCqtf();
    }

    public void updateUi(MineAccount mineAccount) {
        coinMoney.setText("余额：" + mineAccount.getUsable());
        coinMoneyFinan.setText("理财中：" + mineAccount.getLc());
    }

}
